package com.design.prototypepattern.deap;


import java.util.ArrayList;
import java.util.List;

/**
 * @auther LiZiBa
 * @date 2020/8/8 23:51
 * @description:
 **/
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {

        Course course = new Course();
        course.setName("Java desin");
        course.setTime("2020-08-08");
        // 如果在此处未实例则不会开辟堆中的内存，引用无指向，则不会出现问题
        // 若此处设置，则reference == heap 则会出现对象共享
        List<String> teachers = new ArrayList<>();
        teachers.add("TOM");
        course.setTeacher(teachers);

        Course cCourse = course.deapClone();
        cCourse.setName("java springcloud");

        // 注意下方的打印对象
        // 复制的是内存地址
        cCourse.getTeacher().add("mic");

        /**
         * 原对象：Course{name='Java desin', time='2020-08-08', teacher=[TOM, mic]}
         * 克隆对象：Course{name='java springcloud', time='2020-08-08', teacher=[TOM, mic]}
         */

        System.out.println("原对象：" + course);
        System.out.println("克隆对象：" + cCourse);
        System.out.println(course == cCourse);

    }
}
